package com.hissy.common.validate;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

/**
 * Created by zhangyanfei on 2017/10/30.
 * Java Bean 接口参数验证工具类
 * @author zhangyanfei
 * @date 2017/10/30
 */
public class ValidateUtils {
    private static ValidatorFactory factory = Validation.buildDefaultValidatorFactory();

    public static <T> List<String> validate(T t) {
        Validator validator = factory.getValidator();
        Set<ConstraintViolation<T>> constraintViolations = validator.validate(t);
        return constraintViolations.stream()
            .map(ConstraintViolation::getMessage)
            .collect(Collectors.toList());
    }

    // 静态属性  静态内部类

}
